package repository;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author SHUtami
 */

//imported class
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;


public class DatabaseController {
    private String MySQLUser = "progin";
    private String MySQLPass = "progin";
    public Connection konek;

    public void ConnecttoDB(){
        //prosedure to connect to DB
        String connectionUrl = "jdbc:mysql://localhost/kurakura?user="+ MySQLUser+"&password="+MySQLPass;
        try {
            try {
                try {
                    Class.forName("com.mysql.jdbc.Driver").newInstance();
                } catch (InstantiationException ex) {
                    Logger.getLogger(DatabaseController.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IllegalAccessException ex) {
                    Logger.getLogger(DatabaseController.class.getName()).log(Level.SEVERE, null, ex);
                }
            } catch (ClassNotFoundException ex) {
                Logger.getLogger(DatabaseController.class.getName()).log(Level.SEVERE, null, ex);
            }
            Connection con = DriverManager.getConnection(connectionUrl);
            konek = con;
            Statement stmt = null;
            ResultSet rs = null;
            //SQL query command
            String SQL = "USE kurakura";
            stmt = con.createStatement();
            rs = stmt.executeQuery(SQL);
            //System.out.println("Huhu Berhasil Connect");
        } catch (SQLException ex) {
            Logger.getLogger(DatabaseController.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
